package service

import (
	sqlc "bgs/db/sqlc"
	"context"
)

// RefreshBrandDistributeWarehousesByBrandID
func (s *BrandServiceImp) RefreshBrandDistributeWarehousesByBrandID(ctx context.Context, q *sqlc.Queries, brandID int64, warehouseIDs []int64) (err error) {
	err = q.DisableBrandDistributeWarehousesByBrandID(ctx, brandID)
	if err != nil {
		return
	}
	for _, warehouseID := range warehouseIDs {
		err = q.UpsertBrandDistributeWarehouse(ctx, sqlc.UpsertBrandDistributeWarehouseParams{
			BrandID:     brandID,
			WarehouseID: warehouseID,
		})
		if err != nil {
			return
		}
	}
	return
}

// ListBrandDistributeWarehousePtrsByBrandID
func (s *BrandServiceImp) ListBrandDistributeWarehousePtrsByBrandID(ctx context.Context, q *sqlc.Queries, brandID int64) (ptrs []*sqlc.BrandDistributeWarehouse, err error) {
	rows, err := q.ListNormalBrandDistributeWarehousesByBrandID(ctx, brandID)
	if err != nil {
		return
	}
	ptrs = s.MapBrandDistributeWarehouseEntityToPtr(rows)
	return
}
